# -*- coding:utf-8 -*-
from io import BytesIO

from captcha.image import ImageCaptcha

from info.utils import utils


def generate_captcha(length=4):
    v = utils.random_character(length=length)
    image = ImageCaptcha().generate_image(v)
    out = BytesIO()
    image.save(out, format="PNG")
    return out.getvalue(), v
